<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

/**
 * Class CreateWxMassComment
 */
class CreateWxMassComment extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //群发文章列表
        Schema::create('wx_mass_articles', function (Blueprint $table) {
            $table->increments('id')->comment('文章序号');
            $table->unsignedInteger('mass_id')->default(0)->comment('群发消息ID');
            $table->unsignedInteger('msg_id')->default(0)->comment('消息发送任务的ID');
            $table->unsignedInteger('msg_data_id')->default(0)->comment('消息的数据ID');
            $table->unsignedInteger('new_id')->comment('素材图文ID');
            $table->unsignedTinyInteger('index_num')->default(0)->comment('多图文时文章索引');
            $table->string('title', 200)->default('')->comment('文章标题');
            $table->unsignedTinyInteger('open_comment')->default(0)->comment('是否打开评论');
            $table->unsignedInteger('user_declare_state')->default(0)->comment('用户声明文章的状态');
            $table->unsignedTinyInteger('audit_state')->default(0)->comment('系统校验的状态');
            $table->string('original_article_url', 200)->default('')->comment('相似原创文的url');
            $table->unsignedTinyInteger('original_article_type')->default(0)->comment('相似原创文的类型');
            $table->unsignedTinyInteger('can_reprint')->default(0)->comment('是否能转载');
            $table->unsignedTinyInteger('need_replace_content')->default(0)->comment('是否需要替换成原创文内容');
            $table->unsignedTinyInteger('need_show_reprint_source')->default(0)->comment('是否需要注明转载来源');
            $table->unsignedInteger('sync_comment_position')->default(0)->comment('同步评论数目');
            $table->softDeletes();
            $table->timestamps();
            $table->index(['mass_id','deleted_at'],'index1');
            $table->index(['msg_id','deleted_at'],'index2');
            $table->index(['msg_data_id','created_at','deleted_at'],'index3');
        });
        //群发评论
        Schema::create('wx_mass_comments', function (Blueprint $table) {
            $table->increments('id')->comment('评论ID');
            $table->unsignedInteger('mass_id')->default(0)->comment('群发消息ID');
            $table->unsignedInteger('msg_data_id')->default(0)->comment('消息的数据ID');
            $table->unsignedTinyInteger('index_num')->default(0)->comment('多图文时文章索引');
            $table->unsignedInteger('user_comment_id')->default(0)->comment('用户评论id');
            $table->string('around_openid', 100)->default('')->comment('openid');
            $table->mediumText('around_content')->nullable()->comment('评论内容');
            $table->unsignedTinyInteger('around_comment_type')->default(0)->comment('是否精选评论，0为即非精选，1为true，即精选');
            $table->timestamp('around_create_time')->nullable()->comment('评论时间');
            $table->mediumText('reply_content')->nullable()->comment('作者回复内容');
            $table->timestamp('reply_create_time')->nullable()->comment('评论时间');
            $table->softDeletes();
            $table->timestamps();
            $table->index(['user_comment_id','deleted_at'],'index1');
            $table->index(['msg_data_id','index_num','deleted_at'],'index2');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('wx_mass_articles');
        Schema::dropIfExists('wx_mass_comments');
    }
}
